// export  const loadView = (viewPath) => {
//     // 用字符串模板实现动态 import 从而实现路由懒加载
//   return (resolve) => import([`@/view/Page${viewPath}`], resolve) 
//   // return new URL(`@/view/Page${viewPath}.vue`, import.meta.url).href //router4版本
//   // return () => Promise.resolve(require(`@/view/Page${viewPath}.vue`).default) //router4版本
//   }
const modules = import.meta.glob('../view/Page/**/*.vue')
const _import = (path: string) => () => import(`@/view/Page${path}.vue`)
export const getrouteslist = (item1: any) => {
  let routesdata = [];
  let routeschidern = [];
  item1.menu.forEach((item: Object) => {
    var data = {};
    if (!item.children) {
      data = {
        id: item.id,
        path: `${item.path}`,
        name: item.name,

        meta: {
          title: item.meta.title,
          indication: 0,
          icon: item.meta.icon,
        },
        // component:loadView(item.component)

        component: modules[`../view/Page${item.component}.vue`]
        // component:() => import(`@/view/Page${item.component}.vue`)
      };
      // console.log("data.component",data);
      routesdata.push(data);
    } else {
      var data2 = {};
      var data3 = [];
      item.children.forEach((element) => {
        data2 = {
          path: `${element.path}`,
          name: element.name,
          meta: {
            title: element.meta.title,
            indication: element.meta.indication,
          },
          component: modules[`../view/Page${element.component}.vue`],
          // component: loadView(item.component),

        };
        // console.log(element.component);

        data3.push(data2)
      });
      // console.log("data3.component",data3);
      routeschidern.push(data3)
      data = {
        id: item.id,
        path: `${item.path}`,
        name: item.name,
        redirect: item.redirect,
        meta: {
          title: item.meta.title,
          indication: item.meta.indication,
          icon: item.meta.icon,
        },
        children: data3
      };
      routesdata.push(data);
    }
  });
  //   console.log("routesdata",routesdata);
  return routesdata;
};
